package com.xk.meeting.dao;

import com.xk.meeting.entity.Announce;
import com.xk.meeting.utils.ConnectionUtils;
import com.xk.meeting.utils.UtilHelper;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Date;
import java.util.List;

public class AnnounceDaoImpl implements AnnounceDao {
    private JdbcTemplate template = new JdbcTemplate(ConnectionUtils.getDataSource());
    @Override
    public int addAnnounce(String addtext) {
        String sql = "insert into announce values(null,?,?)";
        return template.update(sql, UtilHelper.getTime(),addtext);
    }

    @Override
    public List<Announce> getAnnounceList() {
        String sql = "select * from announce";
        return template.query(sql,new BeanPropertyRowMapper<Announce>(Announce.class));
    }

    @Override
    public int deleteAnnounce(int id) {
        String sql = "delete from announce where id = ?";
        return template.update(sql,id);
    }

    @Override
    public Announce queryAnnounce(int id) {
        String sql = "select * from announce where id = ?";
        return template.queryForObject(sql,new BeanPropertyRowMapper<Announce>(Announce.class),id);
    }

    @Override
    public int updateAnnounce(int id, String content) {
        String sql = "update announce set content = ? where id = ?";
        return template.update(sql,content,id);
    }
}
